#include "MainWindow.h"
#include <NetworkThread.h>

using namespace std;

MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{
    setupUi(this);

/*

  the structure of the main window's central widget

 *---------------------------------------------------*
 |                 central widget                    |
 |                                                   |
 |  *---------------------------*-----------------*  |
 |  |     rendering context     |   scroll area   |  |
 |  |       OpenGL widget       | *-------------* |  |
 |  |                           | | side widget | |  |
 |  |                           | |             | |  |
 |  |                           | |             | |  |
 |  |                           | *-------------* |  |
 |  *---------------------------*-----------------*  |
 |                                                   |
 *---------------------------------------------------*

*/
    _side_widget = new SideWidget(this);

    _scroll_area = new QScrollArea(this);
    _scroll_area->setWidget(_side_widget);
    _scroll_area->setSizePolicy(_side_widget->sizePolicy());
    _scroll_area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

    _gl_widget = new GLWidget(this);

    _layout = new QHBoxLayout(this);
    _layout->addWidget(_gl_widget);
    _layout->addWidget(_scroll_area);

    _central_widget = new QWidget(this);
    _central_widget->setLayout(_layout);

    setCentralWidget(_central_widget);

    connect(_side_widget->connectButton, SIGNAL(clicked()), this, SLOT(slotClientButtonClicked()));
}

void MainWindow::slotClientButtonClicked()
{
    NetworkThread *a = new NetworkThread();
    connect(a, SIGNAL(modsign(float)), this, SLOT(mod(float)));

    a->start();
}

void MainWindow::mod(float value)
{
    _gl_widget->set_trans_x(value);
}

//--------------------------------
// implementation of private slots
//--------------------------------
void MainWindow::on_action_Quit_triggered()
{
    qApp->exit(0);
}

